﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;


namespace MediaRegister
{
    public partial class FormKöpMobil : Form
    {
        
        private struct köpMobil
        {
            public string Nr;
            public string Modell;
            public string Låst;
            public string ImeiNr;
            public string Säljare;
        }

        public int mobil1;
        public FormKöpMobil()
        {
            InitializeComponent();

        }

        public FormKöpMobil(int mobil)
        {
            mobil = mobil1;
            InitializeComponent();
        }
     
        private void button1_Click(object sender, EventArgs e)
        {
            köpMobil köpm;

            köpm.Nr = textBox1.Text;
            köpm.Modell = textBox2.Text;
            köpm.Låst = textBox3.Text;
            köpm.ImeiNr = textBox4.Text;
            köpm.Säljare = textBox5.Text;
            FileStream fs1 = new FileStream(@"M:\KöpMobil.txt", FileMode.Append, FileAccess.Write);
            StreamWriter sr1 = new StreamWriter(fs1);
            sr1.WriteLine(köpm.Nr + " , " + köpm.Modell + " , " + köpm.Låst + " , " + köpm.ImeiNr + " , " + köpm.Säljare);
            foreach (Control t in this.Controls)
                if (t is TextBox)
                    t.Text = " ";
            sr1.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            String s1;
            if (File.Exists(@"M:\KöpMobil.txt"))
            {
                FileStream fs1 = new FileStream(@"M:KöpMobil.txt", FileMode.Open, FileAccess.Read);
                StreamReader sr1 = new StreamReader(fs1);
                s1 = sr1.ReadLine();
                while (s1 != null)
                {
                    listBox1.Items.Add(s1);
                    s1 = sr1.ReadLine();


                }
                sr1.Close();
            }

            else
            {
                MessageBox.Show("Finns ingen fil att visa");
            }
        }

       



        

    }
}
